package cn.moukou.sbzz.service;

import cn.moukou.sbzz.mapper.OrderFromBankMapper;
import cn.moukou.sbzz.pojo.OrderFromBank;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class OrderFromBankService {

    @Autowired
    OrderFromBankMapper orderFromBankMapper;

    public int makeOrder(String bid, String eid, String pid, String detail, String productName) {
        OrderFromBank orderFromBank = new OrderFromBank();
        orderFromBank.setBid(bid);
        orderFromBank.setEid(eid);
        orderFromBank.setPid(pid);
        orderFromBank.setDetail(detail);
        orderFromBank.setStatus(0);
        orderFromBank.setProductName(productName);
        return orderFromBankMapper.insert(orderFromBank);
    }


    public OrderFromBank getOneOrder(String id) {
        return orderFromBankMapper.selectById(id);
    }

    public int authOrder(String id) {
        OrderFromBank orderFromBank = orderFromBankMapper.selectById(id);
        orderFromBank.setStatus(1);
        return orderFromBankMapper.updateById(orderFromBank);
    }

    public List<OrderFromBank> getOrderToMe(String eid, int status) {
        if(status == 0 || status == 1){
            QueryWrapper<OrderFromBank> wrapper = new QueryWrapper<>();
            wrapper.eq("eid", eid);
            wrapper.eq("status", status);
            return orderFromBankMapper.selectList(wrapper);
        } else {
            QueryWrapper<OrderFromBank> wrapper = new QueryWrapper<>();
            wrapper.eq("eid", eid);
            return orderFromBankMapper.selectList(null);
        }
    }

    public List<OrderFromBank> getOrderFromMe(String bid, int status) {
        if(status == 0 || status == 1){
            QueryWrapper<OrderFromBank> wrapper = new QueryWrapper<>();
            wrapper.eq("bid", bid);
            wrapper.eq("status", status);
            return orderFromBankMapper.selectList(wrapper);
        } else {
            QueryWrapper<OrderFromBank> wrapper = new QueryWrapper<>();
            wrapper.eq("bid", bid);
            return orderFromBankMapper.selectList(null);
        }
    }
}
